
package cn.xd.base.persistence.repository.impl;

import cn.xd.base.basic.type.BuriedPointId;
import cn.xd.base.domain.entity.BuriedPoint;
import cn.xd.base.domain.repository.BuriedPointRepository;
import cn.xd.base.persistence.dos.BuriedPointConverter;
import cn.xd.base.persistence.dos.BuriedPointDO;
import cn.xd.base.persistence.mps.BuriedPointMpService;
import cn.xd.core.ddd.db.DbRepositorySupport;
import cn.xd.core.ddd.diff.EntityDiff;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Repository;

/**
 * @author : mirzaLin
 * @data : 2023/11/20
 * @description :
 **/
@Repository
public class BuriedPointRepositoryImpl extends DbRepositorySupport<BuriedPoint, BuriedPointId> implements BuriedPointRepository {
    @Resource
    private BuriedPointMpService buriedPointMpService;

    @Override
    protected void onInsert(BuriedPoint aggregate) {
        buriedPointMpService.saveResult(aggregate, BuriedPointConverter.INSTANCE);
    }

    @Override
    protected BuriedPoint onSelect(BuriedPointId id) {
        return buriedPointMpService.getResult(id, BuriedPointConverter.INSTANCE).get();
    }

    @Override
    protected void onUpdate(BuriedPoint aggregate, EntityDiff diff) {
        if (diff.isSelfModified()) {
            BuriedPointDO bean = diff.getBean(BuriedPointDO.class);
            buriedPointMpService.updateResult(bean);
        }
    }

    @Override
    protected void onDelete(BuriedPoint aggregate) {

    }
}
